package ro.imc.training.Database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBCreate {

	public static final String DERBY_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
	public static final String DATABASE_URL = "jdbc:derby:UMSDatabase;create=true;";

	public DBCreate(){
		try {
			
			
			this.create();      
			
		} catch (InstantiationException | IllegalAccessException
				| ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		}
	}
	
	
	public void create() throws InstantiationException, IllegalAccessException,
			ClassNotFoundException, SQLException {

		Class.forName(DERBY_DRIVER).newInstance();
		Connection conn = DriverManager.getConnection(DATABASE_URL);
		conn.createStatement().execute("DROP TABLE student");
		
		try {
			conn.createStatement()
			.execute(
					"create table student(nume varchar(30), " +
					"prenume varchar(30), " +
					"cnp varchar(13), " +
					"studentno varchar(10)," +
					"status varchar(10)) ");
		} catch(SQLException e) {
			//e.printStackTrace();
		}
		
		
	
		try {
		conn.createStatement()
		.execute(
				"create table profesor(nume varchar(30), " +
				"prenume varchar(30), " +
				"cnp varchar(13), " +
				"field varchar(10)," +
				"title varchar(20)) ");
		} catch(SQLException e) {
			//e.printStackTrace();
		}
		
	
	}

	
	
}
